package org.hook.showcase.pattern.observer.impl;

import java.util.Observable;
import java.util.Observer;

import org.hook.showcase.pattern.observer.DisplayElement;

public class CurrentConditionDisplay2 implements Observer, DisplayElement {
	private Observable observable;
	private float temperature;
	private float humidity;

	public CurrentConditionDisplay2(Observable observable) {
		this.observable = observable;
		this.observable.addObserver(this);
	}

	@Override
	public void update(Observable observable, Object arg) {
		if (observable instanceof WeatherData2) {
			WeatherData2 weatherData = (WeatherData2) observable;
			this.temperature = weatherData.getTemperature();
			this.humidity = weatherData.getHumidity();
			this.display();
		}
	}

	@Override
	public void display() {
		System.out.println("Current conditions:" + this.temperature + "F degrees and " + this.humidity + "% humidity.");
	}
}
